package cn.tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        //1.获取数据库连接     异常抛出
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false",
                "root", "12345");
        //创建执行SQL语句的对象
        Statement s = conn.createStatement();
        //执行插入数据的SQL语句
        //s.executeUpdate("insert into emp(name) values('Tom')");
        //执行修改数据的SQL语句
        //s.executeUpdate("update emp set name='jerry' where name='Tom'");
        //执行删除数据的SQL语句
        //s.executeUpdate("delete from emp where name='jerry'");
        //执行查询数据的SQL语句
        ResultSet rs=s.executeQuery("select * from emp");
        while(rs.next()){
            String name=rs.getString("name");
            double sal=rs.getDouble("sal");
            System.out.println(name+":"+sal);
        }
        //4.关闭资源
        conn.close();
        System.out.println("执行完成!");
    }
}
